19-wrap-up

Professor Shannon Ellis

3/16/23

Wrap-up

Course Announcements

  • Lecture Participation survey “due” after class
  • CS02 due Monday of Finals week (repo due 3/20; survey due 3/21; instructions now on website)
  • Final Project due Th of Finals week (3/23; repo + presentation; survey due 3/24)
  • Please fill out your CAPEs (+0.5% to all grades if 85% of class completes; current: 25%)
  • Post-course survey now available (link also on canvas; due Friday of Finals week; 11:59 PM for EC)
  • CS02 for CS01 score option (details on campuswire)
  • lab this Friday is like an additional open office hours; nothing to turn in
  • OH Finals week…prof office hours days/times? (staff will not hold office hours)
  • if your group wants to present in person on Thurs of finals week, please DM/email me with your group’s time availability that day

Q&A

What questions do you have about data science, stats, R, jobs/internships, etc.?

Next Steps in R

  • Interactive Visualization
  • Package Development
  • Books, Slides, and Personal websites
  • Shiny Apps

Note: Any packages described today ARE allowed to be used for the final project, if you’re going the technical presentation route.

Packages

library(ggplot2)
library(plotly)
library(gganimate)
library(r2d3)
library(gapminder) # the dataset being used

The Data: Gapminder

The gapminder visualization was made famous by Hans Rosling. The dataset used here includes life expectancy, population, and GDP across 142 countries and 5 continents from 1952-2007.

Interactive Viz

plotly, gganimate, and r2d3

plotly

  • wrapper around ggplot plots: ggplotly()
  • when it works, it works
  • less control over specifics
p <- gapminder |>
  filter(year==1977) |>
  ggplot(aes(gdpPercap, lifeExp, size = pop, color=continent)) +
  geom_point() +
  theme_bw()

p <- ggplotly(p)

plotly

gg <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent, frame = year)) +
  geom_point() +
  theme_bw()

gg <- ggplotly(gg) |> 
  highlight("plotly_hover")

gganimate

Extends grammar of graphics for use in animation:

  • transition_*() defines how the data should be spread out and how it relates to itself across time.
  • view_*() defines how the positional scales should change along the animation.
  • shadow_*() defines how data from other points in time should be presented in the given point in time.
  • enter_*()/exit_*() defines how new data should appear and how old data should disappear during the course of the animation.
  • ease_aes() defines how different aesthetics should be eased during transitions.

Source: https://gganimate.com/

  • more control
  • slower to render
  • generates GIFs

For example…

gg <- ggplot(gapminder, aes(gdpPercap, lifeExp, size = pop, color = continent, frame = year)) +
  geom_point() +
  theme_bw() +
  #gganimate specific bits
  labs(title = 'Year: {frame_time}', x = 'GDP per capita', y = 'life expectancy') +
  transition_time(year) +
  ease_aes('linear')

r2d3

  • D3 is a javascript library for producing viz for HTML
  • able to use custom D3 Visualizations within R
  • create D3.js scripts
  • call them from RMarkdown/Shiny/etc.
  • Example here

Package Development

Why develop an R package?

  • reproducibility
  • include data + code
  • organize a project
  • tools needed: devtools and usethis

Books, Slides and Personal Websites

bookdown, xaringan, blogdown, and quarto

An ode to Yihui Xie

Books: bookdown

An R package by Yihui Xie to write online books, with the philosophy that it “should be technically easy to write a book, visually pleasant to view the book, fun to interact with the book, convenient to navigate through the book, straightforward for readers to contribute or leave feedback to the book author(s), and more importantly, authors should not always be distracted by typesetting details”

Slides: xaringan

An RMarkdown extension (based on JS library remark.js) to generate slides from .Rmd documents.

Websites: blogdown

Enables personal website creation using R Markdown and Hugo (or Jekyll)

Quarto

an open-source scientific and technical publishing system built on Pandoc

  • outputs: HTML, PDF, MS Word, ePub, etc.
  • language-agnostic
  • allows for multiple programming languages in a single document
  • Website: Quarto

Other Package Suggestsions

  • Dataviz: handful of packages that extend the functionality of ggplot2; Good Tables: gt, formattable, and reactable
  • Modelling: we only really used the tidymodels and broom packages, so the other packages in tidymodels are options
  • There are lots of packages for doing machine learning. caret is a precursor to tidymodels and good for this
  • Webscraping: rvest
  • Sports: nwslR, baseballr, NFL
  • A whole more curated here

Shiny Apps

Shiny

Shiny is an R package that allows you to build interactive web apps directly from R (initially developed by Winston Chang)

Tidy Tuesday

An online community that works with a new dataset every week. You could continue your R practice. There is a Twitter hashtag to share your work: #TidyTuesday

Note: your first midterm dataset came from Tidy Tuesday.

Your Turn: Get started on one of these…

Always wanted a personal website? Get Started with blogdown! Have a data-centric app you want to share with the world? Shiny it up! Have slides that need to be created for a final project? Give xaringan a go! Have a visualization that needs animation? Make it move!

The Wrap Up

COGS 137: Where We’ve Been

  • R, RMarkdown & RStudio
  • Data Wrangling w/ the tidyverse
  • Dataviz w/ ggplot2
  • CS01: MLR, Multicollinearity & Right to Carry
  • CS02: Logistic Reression & Youth Vaping
  • Next Steps in R: Shiny, bookdown, blogdown, plotly/gganimate

COGS 137: A Semi-New Course

Lots of thanks!

  • course staff! (Shubham, & Christian - feedback, grading, labs, office hours, etc.)
  • all of you (hard work, patience as I returned from parental leave and made more errors than ever…likely due to lack of sleep, flexibility, interest, feedback)
  • Mine Çetinkaya-Rundel, Open Case Studies Team, Posit (RStudio, quarto & tidyverse teams)
  • Sean Kross & Prof Drew Walker

Good Luck on Finals, Get Sleep, Be Safe, Drink Water, Take Care of Yourselves, & Have a Wonderful Spring Break!